using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Typing_GUI.CLASS;

namespace Typing_GUI
{
    public partial class frmManageExam : Form
    {
        public frmManageExam()
        {
            InitializeComponent();
        }
        public int userID;
        private int m_id;

        public int Id
        {
            get { return m_id; }
            set { m_id = value; }
        }
        public void LoadDuLieuCuaExamList()
        {
            dgvExamList.Rows.Clear();
            DataTable dt = CToChucLuyenTap.LayTatCaToChucLuyenTap();
            int stt = 1;
            foreach (DataRow row in dt.Rows)
            {
                DataGridViewRowCollection r = this.dgvExamList.Rows;

                r.Add(stt.ToString(), row["MaLuyenTap"], row["TenLuyenTap"], row["MoTa"]);
                stt++;
            }
            dgvExamList.SelectionMode = DataGridViewSelectionMode.CellSelect;
            dgvExamList.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        }
        public void LoadDuLieu()
        {
            
            //Id = 5;
            string tenNguoiDung = CNguoiDung.LoadThongTinNguoiDung(userID, pbAvatar, pbCapDo);
            lblHoTen.Text = tenNguoiDung;
            ToolTip toolTip1 = new ToolTip();
            toolTip1.SetToolTip(pbCapDo, pbCapDo.Tag.ToString());
            LoadDuLieuCuaExamList();
            
        }
        private void MakeVisibleAgain(object sender, FormClosedEventArgs e)
        {
            this.Visible = true;
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            Form frm = new frmCreateExam();
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.Show();
            
            this.Visible = false;
         
            

        }

        private void frmManageExam_Load(object sender, EventArgs e)
        {
            LoadDuLieu();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

       

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (dgvExamList.SelectedRows.Count > 0)
            {
                for (int i = dgvExamList.SelectedRows.Count - 1; i >= 0; i--)
                {
                    DialogResult dl = MessageBox.Show("Are you sure you want to delete it :" + dgvExamList.SelectedRows[i].Cells[2].Value.ToString(), "Warning !!!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    if (dl == DialogResult.OK)
                    {
                        CToChucLuyenTap toChuc = new CToChucLuyenTap();
                        toChuc.Maluyentap = int.Parse(dgvExamList.SelectedRows[i].Cells[1].Value.ToString());
                        toChuc.deleteTCLT();
                    }
                }
                LoadDuLieu();
            }
            else
            {
                MessageBox.Show("Not choose Exam to delete it !!!"," ERROR !!",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            if (dgvExamList.SelectedRows.Count > 0)
            {
                frmEditExam frm = new frmEditExam();
                frm.MaLuyenTap = int.Parse(dgvExamList.SelectedRows[0].Cells[1].Value.ToString());
                frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
                frm.Show();

                this.Visible = false;
            }
            else
            {
                MessageBox.Show("NotChoose Exam to update !!!","Waning !!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }

       
    }
}